const state = {
  msgInfo: {
    visible: false,
    type: 'error',
    title: '',
    msg: '',
    isConfirm: false, // 是否点击确定关闭
    duration: 2000 // 默认显示2s
  }
}
const mutations = {
  SET_MSGINFO: (state, {
    visible = true,
    type = 'error',
    duration = 2000,
    title = '',
    msg = '',
    isConfirm = false
  }) => {
    const tag = Math.random() * 100 + 1 // 取1-100之间的一个随机数
    state.msgInfo = {
      tag,
      visible,
      type,
      duration: duration || 2000,
      title,
      isConfirm,
      msg
    }
  }
}

const actions = {
  SetMsgInfo({ commit }, obj) {
    commit('SET_MSGINFO', obj)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
